package 字串;

/**
 * @author tmh
 * @date 2024/11/25 21:13
 * @description
 */
public class T560和为K的子数组 {
    public int subarraySum(int[] nums, int k) {
        int count =0;
        for (int i = 0; i < nums.length; i++) {
            int sum = 0;
            //这里是用j=i来实现连续，我一开始想的是j=i+1,这样的话答案不对
            for (int j = i;j<nums.length;j++){
                sum+=nums[j];
                if (sum==k){
                    count++;
                }
            }
        }
        return count;
    }
}
